﻿using AutoMapper;
using CaltechSoft.Service.DBCommand;
using CaltechSoft.Service.EntityFW.Repository;
using CaltechSoft.Service.Infrastructure;
using CaltechSoft.Service.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CaltechSoft.Service.ReportService.Standard
{
    public class StandardReportService : IStandardReportService
    {
        private readonly ICommandExecutor _commandExecutor;

        private readonly IGenericRepository<EntityFW.Entity.CertificateStandard> _certificateStandardGenericRepository;

        public StandardReportService(ICommandExecutor commandExecutor, IGenericRepository<EntityFW.Entity.CertificateStandard> certificateStandardGenericRepository)
        {
            _commandExecutor = commandExecutor;
            _certificateStandardGenericRepository = certificateStandardGenericRepository;
        }

        public SearchResult<CertificateStandardDTO> Search(SearchCriteria.StandardSearchCriteria searchCriteria, int pageSize, int pageIndex)
        {
            return _commandExecutor.Execute(new GetStandardDTODbCommand(searchCriteria, pageSize, pageIndex));
        }

        public StandardModel SearchById(int id)
        {
            var certificateStandard = _certificateStandardGenericRepository.GetByID(id);

            var standard = Mapper.Map<EntityFW.Entity.CertificateStandard, StandardModel>(certificateStandard);
            return standard;
        }
    }
}
